package com.lyEducation.repositoryImpl.base;

import com.lyEducation.entities.base.BaseEntity;
import com.lyEducation.repository.base.BaseRepository;
import com.lyEducation.repositoryImpl.AbstractRepositoryImpl;
import com.lyEducation.util.StringUtils;

public abstract class BaseRepositoryImpl<X extends BaseEntity>
    extends AbstractRepositoryImpl<X, String> implements BaseRepository<X> {
  @Override
  public void softDelete(X entity) {
    if (!entity.getIsDelete()) {
      entity.setIsDelete(true);
    }
    super.update(entity);
  }

  @Override
  public X saveOrUpdate(X entity) {
    if (StringUtils.isBlank((entity.getId()))) {
      save(entity);
    } else {
      update(entity);
    }
    return entity;
  }
}
